package Trash;

import RJZ.Rainbow.Config.Information;
import RJZ.Rainbow.Controller.OrderController;

import java.util.Scanner;

import static java.lang.Thread.sleep;

//@Controller
public class HumanController implements Runnable{
    //@Autowired
    OrderController orderController;
    //@Autowired
    Information imfor;

    @Override
    public void run() {
        Scanner sc1 = new Scanner(System.in);
        System.out.println("验证码线程启动\n");
        while (true){
            try {
                if(orderController.isLink()){
                    System.out.println("请输入指令\n1->投件\n2->取件");
                    if (sc1.hasNext()) {
                        String str = sc1.next();
                        if (str.equals("1")) {
                            System.out.println("请扫描投件码");
                            String code = sc1.next();
                            if(code.equals("")){
                                System.out.println("请勿输入空文本\n");
                            }
                            else {
                                String message1 = "{" +
                                        "\"Cop\":" + "\"110\","
                                        + "\"box_id\":" + "\"" + imfor.getId() + "\","
                                        + "\"code\":" + "\"" + code + "\""
                                        + "}" ;
                                String message=message1+ '\n';
                                orderController.getCh().writeAndFlush(message);
                                System.out.println("发送成功\n");
                                String up = "{" +
                                        "\"Cop\":" + "\"181\","+
                                        "\"box_id\":\"" + imfor.getId()+"\","+
                                        "\"boxlog\":" + message1+
                                        "}" + '\n';
                                orderController.getCh().writeAndFlush(up);
                            }
                        } else if (str.equals("2")) {
                            System.out.println("请扫描取件码");
                            String code = sc1.next();
                            if(code.equals("")){
                                System.out.println("请勿输入空文本\n");
                            }
                            else {
                                String message1 = "{" +
                                        "\"Cop\":" + "\"120\","
                                        + "\"box_id\":" + "\"" + imfor.getId() + "\","
                                        + "\"code\":" + "\"" + code + "\""
                                        + "}" ;
                                String message=message1+ '\n';
                                orderController.getCh().writeAndFlush(message);
                                System.out.println("发送成功\n");
                                String up = "{" +
                                        "\"Cop\":" + "\"181\","+
                                        "\"box_id\":\"" + imfor.getId()+"\","+
                                        "\"boxlog\":" + message1+
                                        "}" + '\n';
                                orderController.getCh().writeAndFlush(up);
                            }
                        }
                    }
                }
                sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
